/**
 * 登录开发
 *
 * @project sky-take-out_1
 * @author MECHREVO
 * @date 2023/12/9 10:17:03
 * @version 1.0
 */
package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.context.BaseContext;
import com.sky.dto.CategoryDTO;
import com.sky.dto.UserLoginDTO;
import com.sky.entity.Category;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.service.DishService;
import com.sky.service.Userservice;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import com.sky.vo.UserLoginVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/user")
public class UserController {
    @Autowired
    private Userservice userservice;
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private DishService dishService;
    /**
     * 登录
     * @param userLoginDTO
     * @return
     */
    @PostMapping("/user/login")
    public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO) {
        log.info("获取授权码：{}", userLoginDTO.getCode());
        UserLoginVO userLoginVO=userservice.login(userLoginDTO.getCode());
        return Result.success(userLoginVO);
    }

    @GetMapping("/category/list")
    public Result selectcategory(Integer type) {
        List<Category> category=categoryService.list(type);
        return Result.success(category);
    }
    @GetMapping("/setmeal/list")
    public Result selectsetmeal(Long categoryId) {
            List<Setmeal> setmeal=userservice.selectsetmeal(categoryId);
        return Result.success(setmeal);
    }
    @GetMapping("/setmeal/dish/{id}")
    public Result selectsetmealdish(Long id) {
        List<DishItemVO> dishItemVO=userservice.selectsetmealdish(id);
        return Result.success(dishItemVO);
    }
    @GetMapping("/dish/list")
    public Result selectdish(Long categoryId) {
        Dish dish=new Dish();
        dish.setCategoryId(categoryId);
        dish.setStatus(StatusConstant.ENABLE);
        List<DishVO> dishVO=dishService.selectdish(dish);
        return Result.success(dishVO);
    }
}
